package de.schlinke_marius.views;

import de.schlinke_marius.R;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;

public class DiagramCanvas extends View {
	
	private float hardwarecosts;
	private float softwarecosts;
	private float personalcosts;
	private float extracosts;

	private int width;
	
	private Context mContext = null;
	private Display display = null;
	private int displayWidth = 0;
	
	private int faktor = 0;
	
	private View pieChart = null;
	private Paint paint;

    public DiagramCanvas(Context context, float hardware, float software, float personal, float extra, int width, int height, double faktor) {
    	super(context);        
    	mContext = context;
    
    	this.hardwarecosts = hardware;
    	this.softwarecosts = software;
    	this.personalcosts = personal;
    	this.extracosts = extra; 
    	
    	paint = new Paint();
		paint.setStyle(Style.FILL);
		paint.setStrokeJoin(Paint.Join.ROUND);
		paint.setStrokeCap(Paint.Cap.ROUND);
		paint.setAntiAlias(true);
    	
    	

    	
		this.display = ((WindowManager) context.getSystemService(context.WINDOW_SERVICE)).getDefaultDisplay();
		displayWidth = display.getWidth();
		this.width = (int) (display.getWidth()*0.6);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        
        float firstSegment = (float) 360 * hardwarecosts/(hardwarecosts+softwarecosts+personalcosts+extracosts);
        float secondSegment = (float) 360 * softwarecosts/(hardwarecosts+softwarecosts+personalcosts+extracosts);
        float thirdSegment = (float) 360 * personalcosts/(hardwarecosts+softwarecosts+personalcosts+extracosts);
        float fourthSegment = (float) 360 * extracosts/(hardwarecosts+softwarecosts+personalcosts+extracosts);
        
 
  
        Paint hardware = new Paint(paint);
        hardware.setColor(mContext.getResources().getColor(R.color.hardware_color));        
        Paint software = new Paint(paint);
        software.setColor(mContext.getResources().getColor(R.color.software_color));
        Paint consulting = new Paint(paint);
        consulting.setColor(mContext.getResources().getColor(R.color.consulting_color));
        Paint extra = new Paint(paint);
        extra.setColor(mContext.getResources().getColor(R.color.extra_color));
       
        
        RectF rect = new RectF((displayWidth-width)/2, 0, displayWidth - ((displayWidth-width)/2) , width);
     
        canvas.drawArc(rect, -90, firstSegment, true, hardware);
        canvas.drawArc(rect, firstSegment-90, secondSegment, true, software);
        canvas.drawArc(rect, firstSegment-90 + secondSegment, thirdSegment, true, consulting);
        canvas.drawArc(rect, firstSegment-90 + secondSegment + thirdSegment, fourthSegment, true, extra);
       
    }
}






